// pages/index/components/myResumeEdit/myResume_edit.js


Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		trigger: {
			type: Boolean,
			default: false
		},
		myresumeEdit: Object
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		// to fill the field
		genderFieldTrigger: false,
		addressFieldTrigger: false,
		preferFieldTrigger: false,
		sel_gender: ['男', '女'],
		preferList: ['全职', '家教', '派单', '其他'],
		preferResult: [],
		arrow: 'arrow',

		// temp data
		name: '',
		age:'',
		gender: '',
		phone: '',
		email:'',
		address: '',
		prefer: [],
		experience: '',
		selfReview: '',
		
		// myresumeEditToEmit: []
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		changeVar: function() {
			this.data.myresumeEdit.name = this.data.name
			this.data.myresumeEdit.age = this.data.age
			this.data.myresumeEdit.phone = this.data.phone
			this.data.myresumeEdit.email = this.data.email
			this.data.myresumeEdit.address = this.data.address
			this.data.myresumeEdit.prefer = this.data.prefer
			this.data.myresumeEdit.experience = this.data.experience
			this.data.myresumeEdit.selfReview = this.data.selfReview
		},
		//保存按钮
		changePropTrigger: function(params) {
				this.changeVar() // 同页面调用函数
				this.triggerEvent('changeTriggerCpn',this.data.myresumeEdit)
				// console.log("cl: ", this.data.gender);
		},
		changeAge: function(e) {
			this.setData({
				age: e.detail
			})
		},
		// 触发picker
		changeFieldTrigger: function(e) {
			if (e.currentTarget.id == 'gender') {
				this.setData({ // 改变视图层数据
					genderFieldTrigger: !this.data.genderFieldTrigger,
				});
				if (e.type == 'confirm') { // 改变属性值
					this.setData({
						gender: e.detail.value
					})
				}
			} else if (e.currentTarget.id == 'address') {
				this.setData({ // 改变视图层数据
					addressFieldTrigger: !this.data.addressFieldTrigger
				})
				let _this = this
				wx.chooseLocation({
					success: function (res) {
						console.log(res);
						_this.setData({
							address: res.address + res.name
						})
						
					},
					fail: function(res) {
						console.log("定位失败", res);
					}
				  })
			}else if (e.currentTarget.id == 'prefer') {
				this.setData({
					preferFieldTrigger: !this.data.preferFieldTrigger,
					// prefer: this.data.preferResult
				});
				if (this.data.preferFieldTrigger) {
					this.setData({
						arrow: 'arrow-down',
					})
				}else {
					this.setData({
						arrow: 'arrow',
					})
				}
			} else if (e.currentTarget.id == 'prefer-gp') {
				this.setData({
					preferResult: e.detail,
				})
				if (e.currentTarget.id == 'prefer-cell') {
					// 选中
					const { index } = e.currentTarget.dataset;
					// const checkbox = this.selectComponent(`.checkboxes-${index}`);
					const checkbox = this.selectAllComponents('.checkboxes-' + index)
					checkbox.toggle();
					console.log(checkbox);
				}
			}
			// console.log(e.detail);
		},
		changeName: function(e) {
			this.setData({
				name: e.detail
			})
		},
		changePhone: function(e) {
			this.setData({
				phone: e.detail
			})
		},
		changeEmail: function(e) {
			this.setData({
				email: e.detail
			})
		},
		changeExperience: function(e) {
			this.setData({
				experience: e.detail
			})
		},
		changeSelfReview: function(e) {
			this.setData({
				selfReview: e.detail
			})
		},
	},
	observers: {
		'preferResult': function(preferResult) {
			this.setData({
				prefer: preferResult
			})
		},
	},
	// 生命周期
	lifetimes: {
		attached: function() {
			this.setData({
				myresumeEditToEmit: this.data.myresumeEdit,
				name: this.data.myresumeEdit.name,
				gender: this.data.myresumeEdit.gender,
				age: this.data.myresumeEdit.age,
				phone: this.data.myresumeEdit.phone,
				email: this.data.myresumeEdit.email,
				address: this.data.myresumeEdit.address,
				prefer: this.data.myresumeEdit.prefer,
				experience: this.data.myresumeEdit.experience,
				selfReview: this.data.myresumeEdit.selfReview,
			});
			this.setData({
				preferResult: this.data.prefer
			})
		},
		detached: function() {
		}
	}
})
